<template>
  <div>
    <el-cascader
      :value="value"
      :options="options"
      :props="fbi"
      separator=" / "
      @change="handleChange"
    />
  </div>
</template>

<script>
import { getDepartment } from '@/api/department'
import { arr2tree } from '@/utils/index'
export default {
  data() {
    return {
      value: {
        type: Number,
        required: true
      },
      fbi: {
        value: 'id',
        label: 'name'
      },
      options: []
    }
  },
  created() {
    this.loadEmployment()
  },
  methods: {
    //  发送请求获取 部门列表
    async loadEmployment() {
      const res = await getDepartment()
      console.log(res)
      const options = arr2tree(res.data, 0)
      this.options = options
    },
    handleChange(value) {
      console.log(value) // value是一个数组
      // 拿到数组最有一个值
      const id = value[value.length - 1]
      console.log(id)
      // 把 id 传给父组件
      this.$emit('input', id)
    }
  }
}

</script>

<style>

</style>
